#include "qtvconnect.h"
#include "ui_qtvconnect.h"


QtVConnect::QtVConnect(QWidget *parent) :
    QWidget(parent),
    _ui(new Ui::QtVConnect)
{

    _ui->setupUi(this);
    _serverSocket = new QTcpSocket(this);
       // connect(_serverSocket, SIGNAL(readyRead()), this, SLOT(donneesRecues()));
       // connect(_serverSocket, SIGNAL(connected()), this, SLOT(connect()));
       //connect(socket, SIGNAL(disconnected()), this, SLOT(deconnecte()));
        //connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(erreurSocket(QAbstractSocket::SocketError)));
}

QtVConnect::~QtVConnect()
{
    delete _ui;
    delete _serverSocket;
}


void QtVConnect::on_connexionButton_clicked(){

   _serverSocket->abort();
   _serverSocket->connectToHost("localhost", 50000);

/*
   //on envoie le pseudo
   QByteArray packet;
   QDataStream out(&packet, QIODevice::WriteOnly);

   QString messageToSend = _pseudo;

   out << (quint16) 0;
   out << messageToSend;
   out.device()->seek(0);
   out << (quint16) (packet.size() - sizeof(quint16));

   _serverSocket->write(packet);
*/
   //on lance l'application de chat
    _application=new QtVisio(this,_ui->pseudo->text());
   _application->setServerSocket(_serverSocket);
   hide();
   _application->show();


}
